package com.caigou.controller.front;

import com.caigou.bean.cms.param.CommentParam;
import com.caigou.bean.cms.param.CommentQueryParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.enums.ResponseEnum;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.ICommentService;
import com.caigou.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/front/comment/")
public class FrontCommentController {
    @Resource
    private ICommentService commentService;

    /**
     *
     * @param param
     * @param user
     * @return
     */
    @PostMapping("/addComment")
    public Result<Integer> addComment(@RequestBody CommentParam param, @CurrentUser Users user) {
        if(user==null){
            return Result.error(ResponseEnum.NO_TOKEN);
        }
        return commentService.addComment(param, user);
    }

    @PostMapping("/listComment")
    public Result listComment(@RequestBody CommentQueryParam param){
        return commentService.listComment(param);
    }
}
